﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:TaxClassAllowance
    /// </summary>
    public partial class TaxClassAllowance
    {
        public TaxClassAllowance()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal FYear, string FTaxClassAllowanceNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from fund.t_TaxClassAllowance");
            strSql.Append(" where FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)			};
            parameters[0].Value = FYear;
            parameters[1].Value = FTaxClassAllowanceNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(EnterpriseFund.Model.TaxClassAllowance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into fund.t_TaxClassAllowance(");
            strSql.Append("FYear,FTaxClassAllowanceNo,FTaxClassNo,FTaxClassAllowanceName,FSQLCondition)");
            strSql.Append(" values (");
            strSql.Append("@FYear,@FTaxClassAllowanceNo,@FTaxClassNo,@FTaxClassAllowanceName,@FSQLCondition)");
            SqlParameter[] parameters = {
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FTaxClassNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FTaxClassAllowanceName", SqlDbType.NVarChar,50),
					new SqlParameter("@FSQLCondition", SqlDbType.NVarChar,-1)};
            parameters[0].Value = model.FYear;
            parameters[1].Value = model.FTaxClassAllowanceNo;
            parameters[2].Value = model.FTaxClassNo;
            parameters[3].Value = model.FTaxClassAllowanceName;
            parameters[4].Value = model.FSQLCondition;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(EnterpriseFund.Model.TaxClassAllowance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxClassAllowance set ");
            strSql.Append("FTaxClassNo=@FTaxClassNo,");
            strSql.Append("FTaxClassAllowanceName=@FTaxClassAllowanceName,");
            strSql.Append("FSQLCondition=@FSQLCondition");
            strSql.Append(" where FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FTaxClassAllowanceName", SqlDbType.NVarChar,50),
					new SqlParameter("@FSQLCondition", SqlDbType.NVarChar,-1),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FTaxClassNo", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.FTaxClassAllowanceName;
            parameters[1].Value = model.FSQLCondition;
            parameters[2].Value = model.FYear;
            parameters[3].Value = model.FTaxClassAllowanceNo;
            parameters[4].Value = model.FTaxClassNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(decimal FYear, string FTaxClassAllowanceNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxClassAllowance ");
            strSql.Append(" where FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)			};
            parameters[0].Value = FYear;
            parameters[1].Value = FTaxClassAllowanceNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxClassAllowance GetModel(decimal FYear, string FTaxClassAllowanceNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FYear,FTaxClassAllowanceNo,FTaxClassNo,FTaxClassAllowanceName,FSQLCondition from fund.t_TaxClassAllowance ");
            strSql.Append(" where FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)			};
            parameters[0].Value = FYear;
            parameters[1].Value = FTaxClassAllowanceNo;

            EnterpriseFund.Model.TaxClassAllowance model = new EnterpriseFund.Model.TaxClassAllowance();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxClassAllowance DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.TaxClassAllowance model = new EnterpriseFund.Model.TaxClassAllowance();
            if (row != null)
            {
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FTaxClassAllowanceNo"] != null)
                {
                    model.FTaxClassAllowanceNo = row["FTaxClassAllowanceNo"].ToString();
                }
                if (row["FTaxClassNo"] != null)
                {
                    model.FTaxClassNo = row["FTaxClassNo"].ToString();
                }
                if (row["FTaxClassAllowanceName"] != null)
                {
                    model.FTaxClassAllowanceName = row["FTaxClassAllowanceName"].ToString();
                }
                if (row["FSQLCondition"] != null)
                {
                    model.FSQLCondition = row["FSQLCondition"].ToString();
                }
                if (row.Table.Columns.Contains("FTaxClassName"))
                {
                    model.FTaxClassName = row["FTaxClassName"].ToString();
                }
            }
            return model;
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxClassAllowance DataRowToModel1(DataRow row)
        {
            EnterpriseFund.Model.TaxClassAllowance model = new EnterpriseFund.Model.TaxClassAllowance();
            if (row != null)
            {
                if (row["FTaxClassAllowanceNo"] != null)
                {
                    model.FTaxClassAllowanceNo = row["FTaxClassAllowanceNo"].ToString();
                }
               
                if (row["FTaxClassAllowanceName"] != null)
                {
                    model.FTaxClassAllowanceName = row["FTaxClassAllowanceName"].ToString();
                }
               
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FYear,FTaxClassAllowanceNo,a.FTaxClassNo,FTaxClassAllowanceName,FSQLCondition,ISNULL(b.FTaxClassShortName,FTaxClassName) AS FTaxClassName ");
            strSql.Append(" FROM fund.t_TaxClassAllowance a left JOIN fund.t_TaxClass b ON a.FTaxClassNo = b.FTaxClassNo  ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList1(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT FTaxClassAllowanceNo
      ,FTaxClassAllowanceName FROM  fund.t_TaxClassAllowance");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" GROUP BY  FTaxClassAllowanceNo ,FTaxClassAllowanceName ");
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FYear,FTaxClassAllowanceNo,FTaxClassNo,FTaxClassAllowanceName,FSQLCondition ");
            strSql.Append(" FROM fund.t_TaxClassAllowance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.t_TaxClassAllowance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FTaxClassAllowanceNo desc");
            }
            strSql.Append(")AS Row, T.*  from fund.t_TaxClassAllowance T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_TaxClassAllowance";
            parameters[1].Value = "FTaxClassAllowanceNo";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

